package com.ticket.sass.provider.controller;

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.provider.annotation.Loggable;
import com.ticket.sass.provider.annotation.Module;
import com.ticket.sass.provider.business.AdminBusiness;
import com.ticket.sass.provider.dto.admin.AdminInfoOutput;
import com.ticket.sass.provider.dto.input.admin.AdminLoginInput;
import com.ticket.sass.provider.model.ResultModel;
import com.ticket.sass.provider.util.JwtUtil;
import com.ticket.sass.provider.util.TokenModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author ywb
 * @date 2022-09-26 17:32
 */
@RestController
@AllArgsConstructor
@ApiSupport(order = 1)
@Api(tags = {"首页-模块"})
public class IndexController {
    
    final JwtUtil jwtUtil;
    final AdminBusiness adminBusiness;
    
    @PostMapping("/login")
    @Loggable(module = Module.ADMIN, desc = "管理员登录")
    @ApiOperation(value = "管理员登录")
    public ResultModel<TokenModel> login(
        @RequestBody @Valid AdminLoginInput input
    ){
        return ResultModel.success(
            adminBusiness.login(input)
        );
    }
    
    @GetMapping("/info")
    @ApiOperation(value = "管理员基本信息")
    public ResultModel<AdminInfoOutput> info(){
        return ResultModel.success(
            adminBusiness.info()
        );
    }
}
